<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>tango.text.convert.Integer</title>
  <link href="./css/style.css" rel="stylesheet" type="text/css"/>
  <!-- <link href="./img/icon.png" rel="icon" type="image/png"/> -->
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/modules.js"></script>
  <script type="text/javascript" src="./js/quicksearch.js"></script>
  <script type="text/javascript" src="./js/navigation.js"></script>
  <!--<script type="text/javascript" src="./js/jquery.treeview.js"></script>-->
  <script type="text/javascript">
    var g_moduleFQN = "tango.text.convert.Integer";
  </script>
  
</head>
<body>
<div id="content">
  <h1><a href="./htmlsrc/tango.text.convert.Integer.html" class="symbol">tango.text.convert.Integer</a></h1>
  
<p class="sec_header">License:</p>BSD style: see <a href="http://www.dsource.org/projects/tango/wiki/LibraryLicense">license.txt</a>
<p class="sec_header">Version:</p>Initial release: Nov 2005
<p class="sec_header">Author:</p>Kris
<p class="bl"/>
        A set of functions for converting between string and integer 
        values. 
<p class="bl"/>
        Applying the D "import alias" mechanism to this module is highly
        recommended, in order to limit namespace pollution:
        <pre class="d_code">
<span class="k">import</span> <span class="i">Integer</span> = <span class="i">tango</span>.<span class="i">text</span>.<span class="i">convert</span>.<span class="i">Integer</span>;

<span class="k">auto</span> <span class="i">i</span> = <span class="i">Integer</span>.<span class="i">parse</span> (<span class="sl">"32767"</span>);
</pre>
<dl>
<dt class="decl">int <a class="symbol _function" name="toInt" href="./htmlsrc/tango.text.convert.Integer.html#L42" kind="function" beg="42" end="43">toInt</a><span class="tparams">(T, U=uint)</span><span class="params">(T[] <em>digits</em>, U <em>radix</em> = 0)</span>; <a title="Permalink to this symbol" href="#toInt" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L42">#</a></dt>
<dd class="ddef">
<div class="summary">Parse an integer value from the provided 'digits' string.</div>
The string is inspected for a sign and an optional radix 
        prefix. A radix may be provided as an argument instead, 
        whereupon it must match the prefix (where present). When
        radix is set to zero, conversion will default to decimal.
<p class="bl"/>
        Throws an exception where the input text is not parsable
        in its entirety.</dd>
<dt class="decl">long <a class="symbol _function" name="toLong" href="./htmlsrc/tango.text.convert.Integer.html#L67" kind="function" beg="67" end="68">toLong</a><span class="tparams">(T, U=uint)</span><span class="params">(T[] <em>digits</em>, U <em>radix</em> = 0)</span>; <a title="Permalink to this symbol" href="#toLong" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L67">#</a></dt>
<dd class="ddef">
<div class="summary">Parse an integer value from the provided 'digits' string.       
        
        The string is inspected for a sign and an optional radix 
        prefix. A radix may be provided as an argument instead, 
        whereupon it must match the prefix (where present). When
        radix is set to zero, conversion will default to decimal.</div>
Throws an exception where the input text is not parsable
        in its entirety.</dd>
<dt class="decl">char[] <a class="symbol _function" name="toString" href="./htmlsrc/tango.text.convert.Integer.html#L89" kind="function" beg="89" end="93">toString</a><span class="params">(long <em>i</em>, char[] <em>fmt</em> = null)</span>; <a title="Permalink to this symbol" href="#toString" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L89">#</a></dt>
<dd class="ddef">
<div class="summary">Wrapper to make life simpler. Returns a text version
        of the provided value.</div>
See format() for details</dd>
<dt class="decl">wchar[] <a class="symbol _function" name="toString16" href="./htmlsrc/tango.text.convert.Integer.html#L104" kind="function" beg="104" end="108">toString16</a><span class="params">(long <em>i</em>, wchar[] <em>fmt</em> = null)</span>; <a title="Permalink to this symbol" href="#toString16" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L104">#</a></dt>
<dd class="ddef">
<div class="summary">Wrapper to make life simpler. Returns a text version
        of the provided value.</div>
See format() for details</dd>
<dt class="decl">dchar[] <a class="symbol _function" name="toString32" href="./htmlsrc/tango.text.convert.Integer.html#L119" kind="function" beg="119" end="123">toString32</a><span class="params">(long <em>i</em>, dchar[] <em>fmt</em> = null)</span>; <a title="Permalink to this symbol" href="#toString32" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L119">#</a></dt>
<dd class="ddef">
<div class="summary">Wrapper to make life simpler. Returns a text version
        of the provided value.</div>
See format() for details</dd>
<dt class="decl">T[] <a class="symbol _function" name="format" href="./htmlsrc/tango.text.convert.Integer.html#L163" kind="function" beg="163" end="164">format</a><span class="tparams">(T, U=long)</span><span class="params">(T[] <em>dst</em>, U <em>i</em>, T[] <em>fmt</em> = null)</span>; <a title="Permalink to this symbol" href="#format" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L163">#</a></dt>
<dd class="ddef">
<div class="summary">Supports format specifications via an array, where format follows
        the notation given below:
        <pre class="d_code">
<span class="i">type</span> <span class="i">width</span> <span class="i">prefix</span>
</pre></div>
Type is one of [d, g, u, b, x, o] or uppercase equivalent, and
        dictates the conversion radix or other semantics.
<p class="bl"/>
        Width is optional and indicates a minimum width for zero-padding,
        while the optional prefix is one of ['#', ' ', '+'] and indicates
        what variety of prefix should be placed in the output. e.g.
        <pre class="d_code">
<span class="sl">"d"</span>     =&gt; <span class="i">integer</span>
<span class="sl">"u"</span>     =&gt; <span class="i">unsigned</span>
<span class="sl">"o"</span>     =&gt; <span class="i">octal</span>
<span class="sl">"b"</span>     =&gt; <span class="i">binary</span>
<span class="sl">"x"</span>     =&gt; <span class="i">hexadecimal</span>
<span class="sl">"X"</span>     =&gt; <span class="i">hexadecimal</span> <span class="i">uppercase</span>

<span class="sl">"d+"</span>    =&gt; <span class="i">integer</span> <span class="i">prefixed</span> <span class="k">with</span> <span class="sl">"+"</span>
<span class="sl">"b#"</span>    =&gt; <span class="i">binary</span> <span class="i">prefixed</span> <span class="k">with</span> <span class="sl">"0b"</span>
<span class="sl">"x#"</span>    =&gt; <span class="i">hexadecimal</span> <span class="i">prefixed</span> <span class="k">with</span> <span class="sl">"0x"</span>
<span class="sl">"X#"</span>    =&gt; <span class="i">hexadecimal</span> <span class="i">prefixed</span> <span class="k">with</span> <span class="sl">"0X"</span>

<span class="sl">"d8"</span>    =&gt; <span class="i">decimal</span> <span class="i">padded</span> <span class="i">to</span> <span class="n">8</span> <span class="i">places</span> <span class="i">as</span> <span class="i">required</span>
<span class="sl">"b8"</span>    =&gt; <span class="i">binary</span> <span class="i">padded</span> <span class="i">to</span> <span class="n">8</span> <span class="i">places</span> <span class="i">as</span> <span class="i">required</span>
<span class="sl">"b8#"</span>   =&gt; <span class="i">binary</span> <span class="i">padded</span> <span class="i">to</span> <span class="n">8</span> <span class="i">places</span> <span class="i">and</span> <span class="i">prefixed</span> <span class="k">with</span> <span class="sl">"0b"</span>
</pre>
<p class="bl"/>
        Note that the specified width is exclusive of the prefix, though
        the width padding will be shrunk as necessary in order to ensure
        a requested prefix can be inserted into the provided output.</dd>
<dt class="decl">long <a class="symbol _function" name="parse" href="./htmlsrc/tango.text.convert.Integer.html#L337" kind="function" beg="337" end="338">parse</a><span class="tparams">(T, U=uint)</span><span class="params">(T[] <em>digits</em>, U <em>radix</em> = 0, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#parse" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L337">#</a></dt>
<dd class="ddef">
<div class="summary">Parse an integer value from the provided 'digits' string.</div>
The string is inspected for a sign and an optional radix 
        prefix. A radix may be provided as an argument instead, 
        whereupon it must match the prefix (where present). When
        radix is set to zero, conversion will default to decimal.
<p class="bl"/>
        A non-null 'ate' will return the number of characters used
        to construct the returned value.</dd>
<dt class="decl">ulong <a class="symbol _function" name="convert" href="./htmlsrc/tango.text.convert.Integer.html#L364" kind="function" beg="364" end="365">convert</a><span class="tparams">(T, U=uint)</span><span class="params">(T[] <em>digits</em>, U <em>radix</em> = 10, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#convert" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L364">#</a></dt>
<dd class="ddef">
<div class="summary">Convert the provided 'digits' into an integer value,
        without checking for a sign or radix. The radix defaults
        to decimal (10).</div>
Returns the value and updates 'ate' with the number of
        characters consumed.</dd>
<dt class="decl">uint <a class="symbol _function" name="trim" href="./htmlsrc/tango.text.convert.Integer.html#L414" kind="function" beg="414" end="415">trim</a><span class="tparams">(T, U=uint)</span><span class="params">(T[] <em>digits</em>, inout bool <em>sign</em>, inout U <em>radix</em>)</span>; <a title="Permalink to this symbol" href="#trim" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L414">#</a></dt>
<dd class="ddef">
<div class="summary">Strip leading whitespace, extract an optional +/- sign,
        and an optional radix prefix. If the radix value matches
        an optional prefix, or the radix is zero, the prefix will
        be consumed and assigned. Where the radix is non zero and
        does not match an explicit prefix, the latter will remain 
        unconsumed. Otherwise, radix will default to 10.</div>
Returns the number of characters consumed.</dd>
<dt class="decl">uint <a class="symbol _function" name="atoi" href="./htmlsrc/tango.text.convert.Integer.html#L488" kind="function" beg="488" end="498">atoi</a><span class="tparams">(T)</span><span class="params">(T[] <em>s</em>, int <em>radix</em> = 10)</span>; <a title="Permalink to this symbol" href="#atoi" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L488">#</a></dt>
<dd class="ddef">
<div class="summary">quick &amp; dirty text-to-unsigned int converter. Use only when you
        know what the content is, or use parse() or convert() instead.</div>
Return the parsed uint</dd>
<dt class="decl">T[] <a class="symbol _function" name="itoa" href="./htmlsrc/tango.text.convert.Integer.html#L511" kind="function" beg="511" end="512">itoa</a><span class="tparams">(T, U=uint)</span><span class="params">(T[] <em>output</em>, U <em>value</em>, int <em>radix</em> = 10)</span>; <a title="Permalink to this symbol" href="#itoa" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Integer.html#L511">#</a></dt>
<dd class="ddef">
<div class="summary">quick &amp; dirty unsigned to text converter, where the provided output
        must be large enough to house the result (10 digits in the largest
        case). For mainstream use, consider utilizing format() instead.</div>
Returns a populated slice of the provided output</dd></dl>
</div>
<div id="footer">
  <p>Copyright (c) 2004 Kris Bell. All rights reserved</p>
  <p>Page generated by <a href="http://code.google.com/p/dil">dil</a> on Fri Dec 26 04:04:47 2008. Rendered by <a href="http://code.google.com/p/dil/wiki/Kandil">kandil</a>.</p>
</div>
</body>
</html>